package com.xiaoxx.controller.sys;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaoxx.annotation.LogRecords;
import com.xiaoxx.common.result.R;
import com.xiaoxx.model.dto.sys.SysMsgPublishDto;
import com.xiaoxx.model.vo.sys.SysMsgPublishListVo;
import com.xiaoxx.model.vo.sys.SysMsgPublishQuery;
import com.xiaoxx.model.vo.sys.SysMsgPublishVo;
import com.xiaoxx.service.SysMsgPublishService;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HX
 * @since 2023-08-03
 */
@Validated
@RestController
@Api(value = "SysMsgPublishController", tags = "消息发送")
@RequestMapping("/api/sys/msgPublish")
public class SysMsgPublishController {

    @Resource
    private SysMsgPublishService msgPublishService;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation(value = "查询发送列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "query", value = "查询角色列表", required = true, dataType = "SysLogQuery", paramType = "Body")})
    @ApiResponses(value = {@ApiResponse(response = SysMsgPublishListVo.class, code = 200, message = "响应成功")})
    public R<IPage<SysMsgPublishListVo>> list(@RequestBody SysMsgPublishQuery query) {
        return R.success(msgPublishService.listMsgPublish(query));
    }

    @RequestMapping(value = "/addOrUpd", method = RequestMethod.POST)
    @ApiOperation(value = "添加修改消息")
    @ApiImplicitParams({@ApiImplicitParam(name = "dto", value = "添加或修改消息", required = true, dataType = "SysMsgPublishDto", paramType = "Body")})
    @ApiResponses(value = {@ApiResponse(response = String.class, code = 200, message = "响应成功")})
    @LogRecords(moduleName = "消息管理", content = "添加或修改消息")
    public R<Boolean> add(@RequestBody SysMsgPublishDto dto) {
        return R.success(msgPublishService.addOrUpd(dto));
    }

    @RequestMapping(value = "/del", method = RequestMethod.DELETE)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "消息发送id", required = true, dataType = "String", paramType = "query")})
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @LogRecords(moduleName = "消息管理", content = "删除消息发送记录")
    public R<Boolean> del(@RequestParam String id) {
        //删除消息发送记录
        Boolean b = msgPublishService.removeById(id);
        return R.success(b);
    }


    @RequestMapping(value = "/findById", method = RequestMethod.GET)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "消息发送id", required = true, dataType = "String", paramType = "query")})
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    public R<SysMsgPublishVo> findById(@RequestParam String id) {
        return R.success(msgPublishService.getById(id).convert(SysMsgPublishVo.class));
    }

    @RequestMapping(value = "/sendAgain", method = RequestMethod.GET)
    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "消息发送id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "userIds", value = "用户id", required = true, dataType = "List", paramType = "query")})
    @ApiOperation(value = "再次发送", notes = "再次发送")
    public R<Boolean> sendAgain(@RequestParam String id, @RequestParam List<String> userIds) {
        return R.success(msgPublishService.sendAgain(id, userIds));
    }
}

